package gulimall.config;

import org.omg.CORBA.OBJECT_NOT_EXIST;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @author HLF
 * @date 2022/8/11 20:25
 */
@EnableRedisHttpSession   //开启SpringSession的支持
@Configuration
public class SpringSessionConfig {
    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();
        //设置父域
        defaultCookieSerializer.setDomainName("firstgulimall.com");
        //设置Cookie的名字,类似于JSESSIONID
        defaultCookieSerializer.setCookieName("GULIMALLSESSION");
        return defaultCookieSerializer;
    }

    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        return new Jackson2JsonRedisSerializer<>(Object.class);
    }
}
